<!--用于编辑界面右边是地图，规划路线，直接在地图显示-->
<template>
    <div class="input_map">
        <my-input :id="id" isChange="Y" @input="changeInput" :exkey="exkey" :extype="extype"  class='myInputs' :data="data" :isRequired="isRequired"  :appid="appid"></my-input>
        <el-button type="primary" :loading="loading" class="butttonSelect" @click="createLx" style="margin-left:5px">规划路线</el-button>
        
    </div>
</template>
<script>
import myInput  from './myInput'
export default {
    props:['exkey','extype','id','label','data','appid','dataField','isRequired'],
    inject:["setCarMap"],    //接收一个方法
    components:{
        myInput
        
    },
    data(){
        return{
            loading:false
        }
    },
    create(){
        let ids=this.id.split(".");
        let pId=ids[0];
        let cId=ids[1]
    },
    methods:{
        createLx(){
            
            if(this.exkey&&this.exkey.map.url){
                this.loading=true;
                let url=this.exkey.map.url;
                let params=this.exkey.map.params;
                let paramss={};
                let setData=this.exkey.map.setData;

                let isOk=true;
                let msg=""
                params.forEach(item=>{
                    let key =item.key;
                    let field=item.field.split(",");
                    let isEmpty=item.isEmpty;
                    let pre=item.pre;
                    
                    let val="";
                    field.forEach(ff=>{
                    let val_= this.data[pre][ff]
                    val+=val_;
                    })
                    if(isEmpty=="N"&&!val){
                        isOk=false;
                        msg=item.msg;
                    }
                    paramss[key]=val;
                })
                if(isOk){
                    this.$post("",url,paramss).then(data=>{
                        //try{
                            this.setCarMap(data,setData,url)
                        //}catch(e){}
                       
                        if(setData){
                            setData.forEach(item=>{
                                let dstField=item.dstField.split(".");
                                let srcField=item.srcField;
                                this.$set(this.data[dstField[0]],dstField[1],data[srcField]);
                            })
                        }
                        this.loading=false;
                        
                    })
                }else{
                    this.loading=false;
                    this.$alert(msg, '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            
                        }
                    });
                }
                
            }
        }
    }
}
</script>
<style scoped>
.input_map{
    display:flex;
    flex-direction: row;
    width:100%;
    overflow: hidden;
}
.myInputs{
    flex:1;
}

.dialog_main{
    display: flex;
    flex-direction: row;
}
.dialog_right{
    flex:1;
}
.dialog_left{
    width:200px;
    overflow:auto;
}
.dialog_left_item{
    padding:5px;
    border-bottom:1px solid #ddd;
    cursor:pointer;
}
.dialog_left_item:hover{
    background:#3687e1;
    color:#fff;
}
.dialog_left_active{
    background:#3687e1;
    color:#fff;
}
</style>
